package com.wr.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wr.pojo.TArticle;
import com.wr.repository.TArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王瑞
 * @description:
 * @date 2020/2/27  19:25
 */
@Service
public class TArticleService {
    @Autowired
    private TArticleRepository tArticleRepository;

    @Autowired
    private RedisTemplate redisTemplate;


    public Integer findPage() {
        Object findPage = redisTemplate.opsForValue().get("findPage");
        System.out.println(findPage);
        if (findPage != null) {
            int i = new Double((Double) findPage).intValue();
            return i;
        } else {
            List<TArticle> all = tArticleRepository.findAll();
            int size = all.size();
            double s = new Double(size);
            double ceil = Math.ceil(s / 3);

            redisTemplate.opsForValue().set("findPage", ceil);

            return new Double(ceil).intValue();
        }
    }

    public List<TArticle> findLimit(Integer startNo, Integer limitTotle) {
        return tArticleRepository.findLimit(startNo, limitTotle);

    }


}
